<template>
	<view class="content">
		<u-datetime-picker 
			:show="showStart" 
			v-model="timeStamp" 
			closeOnClickOverlay mode="date"
			@confirm="confirmStart" 
			@cancel="showStart = false" 
			@close="showStart = false">
		</u-datetime-picker>
		<mescroll-uni ref="mescrollRef" @init="mescrollInit" bottom="120" @up="upCallback" :up="upOption" :down="{use: false}">
		<view class="section-0">
			<view class="section-body">
				<view class="frequency"><text class="label">会议次数：</text><text class="number">{{total}}</text>次</view>
			</view>
		</view>
		<view class="section-1">
			<view class="form">
				<view class="time-part">
					<div class="form-item">
						<view class="input">
							<view class="input-body" @click="showDate('start_time')">{{form.start_time}}</view>
							<view class="iconfont icon-rili"></view>
						</view>
					</div>
					<view class="shape">-</view>
					<div class="form-item">
						<view class="input">
							<view class="input-body" @click="showDate('end_time')">{{form.end_time}}</view>
							<view class="iconfont icon-rili"></view>
						</view>
					</div>
				</view>
				<view class="actions">
					<view class="action" @click="handleResetForm()">
						<text>重</text>
						<text>置</text>
					</view>
					<view class="action search" @click="handleSearch()">
						<text>查</text>
						<text>询</text>
					</view>
				</view>
			</view>
			<view class="list">
				<view @click="go(item)" class="item" v-for="item in list" :key="item.id">
					<view class="person">{{item.meet_name}}<view class="status">{{item.status ? '已召开' : '待召开'}}</view></view>
					<view class="iconfont icon-xiangyou1"></view>
				</view>
			</view>
		</view>
		</mescroll-uni>
		<view class="custom-button" @click="add()">+ 召开安委会</view>
	</view>
</template>

<script>
	import { committeeListApi } from '@/api/statistics.js';
	import { mapGetters, mapActions} from 'vuex';
	export default {
		data() {
			return {
				user_name: '',
				total: 0,
				list:[],
				form: {
					start_time: '',
					end_time: ''
				},
				showStart: false,
				timeType: '',
				timeStamp: '',
				type: '',
				mescroll: null, // mescroll实例对象 (此行可删,mixins已默认)
				upOption:{
					textNoMore: '-- 没有更多了 --'
				},
				pageSize:20,
			};
		},
		methods:{
			showDate(type) {
				this.timeType = type;
				this.showStart = true;
			},
			closeDate(type) {
				this.timeType = '';
				this.showStart = false;
			},
			formatDate(timeStamp) {
				const date = new Date(timeStamp); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
				const Y = date.getFullYear() + '-';
				const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
				const D = date.getDate();
				const h = date.getHours() + ':';
				const m = date.getMinutes() + ':';
				const s = date.getSeconds();
				return Y + M + D;
			},
			confirmStart(val) {
				const timeStamp = val.value;
				this.form[this.timeType] = this.formatDate(timeStamp);
				this.closeDate();
			},
			go(item) {
				const params = JSON.stringify(item);
				if (this.type === 'work') {
					uni.navigateTo({
						url: '/pages/statistics/safety/committee/edit/index?params=' + params
					})
				} else {
					uni.navigateTo({
						url: '/pages/statistics/safety/committee/info/index?params=' + params
					})
				}
				
			},
			add() {
				uni.navigateTo({
					url: '/pages/statistics/safety/committee/add/index'
				})
			},
			handleResetForm(){
				for (let key in this.form) {
					this.form[key] = '';
				}
				this.mescroll.resetUpScroll();
this.mescroll.scrollTo(0,0);
			},
			handleSearch(){
				this.mescroll.resetUpScroll();
this.mescroll.scrollTo(0,0);
			},
			/*mescroll组件初始化的回调,可获取到mescroll对象 (此处可删,mixins已默认)*/
			mescrollInit(mescroll) {
				this.mescroll = mescroll;
			},
			/*上拉加载的回调*/
			async upCallback(page) {
				const {data} =  await committeeListApi({
					...this.form,
					page: page.num,
					pageSize: this.pageSize
				});
				
				if (data.code === 1 || data.code === 200) {
					this.total = data.data.total;
					// 接口返回的当前页数据列表 (数组)
					let curPageData =  data.data.data; 
					// 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
					let curPageLen = curPageData.length; 
					// 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
					let totalPage = data.data.last_page; 
					//设置列表数据
					if(page.num == 1) this.list = []; //如果是第一页需手动置空列表
					this.list = this.list.concat(curPageData); //追加新数据
					// 请求成功,隐藏加载状态
					this.mescroll.endByPage(curPageLen, totalPage); 
					setTimeout(()=>{
						this.mescroll.endSuccess(curPageLen);
					},20);
				} else{
					//  请求失败,隐藏加载状态
					this.mescroll.endErr()
				}
			},
			// async fetchData() {
			// 	uni.showLoading({title: '加载中...'});
			// 	const { data } = await committeeListApi({...this.form});
			// 	uni.hideLoading();
			// 	if (data.code === 1) {
			// 		this.list = data.data.list;
			// 		this.total = data.data.total;
			// 	} 
			// }
		},
		onReady() {
			this.timeStamp = (new Date()).valueOf();
			// this.fetchData();
		},
		onLoad(data) {
			// 判断工作台还是统计页面过来的
			this.type = data.type;
		}
	}
</script>

<style lang="scss" scoped>
	.custom-button {
		position: fixed;
		left: 0;
		right: 0;
		margin: 0 auto;
		bottom: 40rpx;
		box-shadow: 0rpx 13rpx 35rpx 0rpx 
				rgba(60, 90, 214, 0.42);
	}
	.content{
		background-color: #fff;
	}
	
	.section-1{
		position: relative;
		top: -50rpx;
		z-index: 10;
		background-color: #fff;
		border-top-left-radius: 50rpx;
		border-top-right-radius: 50rpx;
		.list{
			width: 100%;
			box-sizing: border-box;
			box-shadow: 0rpx 10rpx 20rpx 0rpx rgba(0, 0, 0, 0.05) inset;
			padding: 0 40rpx;
			padding-top: 30rpx;
			.add-committee{
				font-size: 26rpx;
				font-weight: normal;
				font-stretch: normal;
				line-height: 49rpx;
				letter-spacing: 0rpx;
				color: #0535d6;
				height: 70rpx;
				line-height: 70rpx;
				padding-left: 40rpx;
			}
			.item{
				width: 100%;
				height: 82rpx;
				border-bottom: solid 2rpx #f2f2f0;
				line-height: 82rpx;
				padding-left: 45rpx;
				padding-right: 35rpx;
				box-sizing: border-box;
				position: relative;
				.person{
					float: left;
					width: 470rpx;
					font-size: 26rpx;
					font-weight: normal;
					font-stretch: normal;
					letter-spacing: 2rpx;
					color: #3b3c40;
					text-overflow: ellipsis;
					overflow: hidden;
					white-space: nowrap;
					text{
						height: 25rpx;
						border-radius: 12rpx;
						border: solid 1rpx #ffdc00;
						text-align: center;
						line-height: 25rpx;
						font-size: 14rpx;
						line-height: 25rpx;
						letter-spacing: 0rpx;
						color: #ffdc00;
						margin-left: 18rpx;
						display: inline-block;
						padding: 0 10rpx;
						position: relative;
						top: -5rpx;
					}
				}
				.status{
					display: inline-block;
					padding: 0 12rpx;
					border: 1rpx solid #ffdc00;
					height: 26rpx;
					line-height: 26rpx;
					font-size: 16rpx;
					color: #ffdc00;
					border-radius: 13rpx;
					margin-left: 13rpx;
				}
				.num{
					float: right;
					min-width: 46rpx;
					height: 46rpx;
					margin-top: 18rpx;
					border-radius: 28rpx;
					line-height: 46rpx;
					text-align: center;
					font-size: 26rpx;
					font-weight: bold;
					color: #395cf5;
					background: #ffde00;
					margin-right: 40rpx;
					
				}
				.iconfont{
					float: right;
					font-size: 30rpx;
				}
			}
		}
		.actions{
			width: 100%;
			height: 50rpx;
			margin-top: 29rpx;
			padding-bottom: 40rpx;
			display: flex;
			justify-content: space-between;
			.action{
				width: 288rpx;
				height: 48rpx;
				background-color: #395cf5;
				border-radius: 20rpx;
				text-align: center;
				line-height: 48rpx;
				font-size: 26rpx;
				font-weight: normal;
				font-stretch: normal;
				color: #ffffff;
				text{
					&:first-child{
						margin-right: 20rpx;
					}
				}
			}
			.search{
				background-color: #1534ce;
			}
		}
		.form{
			width: 100%;
			padding: 0 75rpx;
			padding-top: 40rpx;
			box-sizing: border-box;
			.form-item{
				width: 600rpx;
				height: 48rpx;
				border-radius: 20rpx;
				border: solid 2rpx #1534ce;
				margin: 0 auto;
				margin-bottom: 34rpx;
				@include clear();
				.input{
					width: 100%;
					height: 100%;
					.input-body{
						width: 100%;
						height: 100%;
					}
				}
			}
			.time-part {
				width: 100%;
				height: 48rpx;
				border-radius: 20rpx;
				border: solid 2rpx #1534ce;
				display: flex;
				margin-bottom: 24rpx;
				justify-content: space-between;
			
				.form-item {
					width: 40%;
					border: none;
					position: relative;
					padding-left: 10rpx;
					font-size: 26rpx;
					line-height: 48rpx;
					letter-spacing: 0rpx;
					color: rgba(0,0,0,0.7);
				}
			
				.shape {
					height: 48rpx;
					line-height: 48rpx;
					color: #1534ce;
				}
				
				.iconfont {
					position: absolute;
					right: 25rpx;
					top: 0rpx;
					font-size: 30rpx;
					color: #dad9df;
				}
			}
		}
	}
	.section-0{
		width: 100%;
		background-color: #2e5efe;
		.section-body{
			width: 100%;
			padding-left: 75rpx;
			height: 150rpx;
			padding-right: 40rpx;
			padding-bottom: 50rpx;
			background-color: #1534ce;
			background-size: cover;
			background-repeat: no-repeat;
			border-top-left-radius: 50rpx;
			border-top-right-radius: 50rpx;
			overflow: hidden;
			box-sizing: border-box;
			.frequency{
				width: 100%;
				height: 100rpx;
				line-height: 100rpx;
				font-size: 26rpx;
				color: #87c6ff;
				.label{
					color: #fff;
				}
				.number{
					margin-left: 25rpx;
					margin-right: 15rpx;
					font-size: 70rpx;
					font-weight: bold;
					font-stretch: normal;
					letter-spacing: 0rpx;
					color: #ffdc00;
				}
			}
			.item{
				width: 33.33%;
				float: left;
				display: flex;
				flex-wrap: wrap;
				align-content: space-between;
				padding-top: 40rpx;
				height: 100rpx;
				position: relative;
				.shape{
					width: 4rpx;
					height: 84rpx;
					background-image: linear-gradient(rgba(#3658f2, 0.3) 0%, #3658f2 30%, #3658f2 70%, rgba(#3658f2, 0.3) 100%,);
					position: absolute;
					right: 0;
					top: 48rpx;
				}
				.top{
					width: 100%;
					text-align: center;
					font-size: 16rpx;
					font-weight: normal;
					font-stretch: normal;
					letter-spacing: 0rpx;
					color: #95c4fa;
				}
				.bottom{
					width: 100%;
					text-align: center;
					font-size: 58rpx;
					font-weight: bold;
					font-stretch: normal;
					letter-spacing: 0rpx;
					color: #ffde00;
				}
			}
		}
	}
</style>
